﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region ReceivableDetailDao

        public List<tb_ReceivableDetail> GetAllReceivableDetail()
        {

            var query = (from obj in this.tb_ReceivableDetails
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }

        public tb_ReceivableDetail GetReceivableDetailById(int id)
        {
            return this.tb_ReceivableDetails.SingleOrDefault(tb_ReceivableDetails => tb_ReceivableDetails.Id == id);
        }

        public List<tb_ReceivableDetail> GetReceivableDetailsByReceivableId(int receivableId)
        {

            var query = (from obj in this.tb_ReceivableDetails
                         where obj.IsDelete == 0 && obj.ReceivableId == receivableId                          
                         select obj).ToList();
            return query;
        }

        public void CreateReceivableDetail(tb_ReceivableDetail entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_ReceivableDetails.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyReceivableDetail(tb_ReceivableDetail entity)
        {
            tb_ReceivableDetail instance = this.tb_ReceivableDetails.SingleOrDefault(p => p.Id == entity.Id);
            instance.Amount = entity.Amount;
            instance.ReceivableId = entity.ReceivableId;
            instance.ReceivableType = entity.ReceivableType;
            instance.Id = entity.Id;
            instance.IsDelete = entity.IsDelete; 

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }
        public void DeleteReceivableDetail(tb_ReceivableDetail entity)
        {
            tb_ReceivableDetail deleteEntity = tb_ReceivableDetails.SingleOrDefault(p => p.Id == entity.Id);
            tb_ReceivableDetails.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }
}
